<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div>
	<script type="text/javascript">
		function fmt(date){
			if(arguments.length == 0 || !date){
				return "";
			}
			var dateVal = null;
			var year = null;
			var month = null;
			var datev = null;
			var hour = null;
			var minute = null;
			var second = null;
			var yearStr = null;
			var monthStr = null;
			var dateStr = null;
			var hourStr = null;
			var minuteStr = null;
			var secondStr = null;
			if(typeof date == 'object') {
				dateVal = date;
			} else if(typeof date == 'number'){
				if(date.toString().length == 10) {
					dateVal = new Date(date * 1000);
				}else{
				    dateVal = new Date(date);
				}
			} else if(typeof date == 'string'){
				var len = date.toString().length;
				if(len == 8){
					yearStr = date.substring(0,4);
					monthStr = date.substring(4,6);
					dateStr = date.substring(6,8);
					hourStr = "00";
					minuteStr = "00";
					secondStr = "00";
				} else if(len == 10) {
				   if(date.indexOf("-") != -1 || date.indexOf("/") != -1 || date.indexOf(".") != -1) {
					  yearStr = date.substring(0,4);
					  monthStr = date.substring(5,7);
					  dateStr = date.substring(8,10);
					  hourStr = "00";
					  minuteStr = "00";
					  secondStr = "00";
				   } else {
					  dateVal = new Date(date * 1000);
				   }	
				} else if(len == 13) {
					dateVal = new Date(parseInt(date));
				} else if(len == 14) {
					yearStr = date.substring(0,4);
					monthStr = date.substring(4,6);
					dateStr = date.substring(6,8);
					hourStr = date.substring(8,10);
					minuteStr = date.substring(10,12);
					secondStr = date.substring(12,14);
				} else if(len == 15) {
					yearStr = date.substring(0,4);
					monthStr = date.substring(4,6);
					dateStr = date.substring(6,8);
					hourStr = date.substring(9,11);
					minuteStr = date.substring(11,13);
					secondStr = date.substring(13,15);
				} else if(len == 19) {
					yearStr = date.substring(0,4);
					monthStr = date.substring(5,7);
					dateStr = date.substring(8,10);
					hourStr = date.substring(11,13);
					minuteStr = date.substring(14,16);
					secondStr = date.substring(17,19);
				} else if(len == 23) {
					yearStr = date.substring(0,4);
					monthStr = date.substring(5,7);
					dateStr = date.substring(8,10);
					hourStr = date.substring(11,13);
					minuteStr = date.substring(14,16);
					secondStr = date.substring(17,19);					
				}
			} else if(typeof date == 'boolean'){
				if(date == false){
					return "";
				} else{
					dateVal = new Date();
				}
			}
			if(yearStr != null) {
				return yearStr + "-" + monthStr + "-" + dateStr + " " + hourStr + ":" + minuteStr + ":" + secondStr;
			}
			if(dateVal != null) {
				year = dateVal.getFullYear();
				month = dateVal.getMonth() + 1;
				datev = dateVal.getDate();
				hour = dateVal.getHours();
				minute = dateVal.getMinutes();
				second = dateVal.getSeconds();
				if(year >= 0 && year < 10) {
					yearStr = "000" + year;
				} else if(year >= 10 && year < 100) {
					yearStr = "00" + year;
				} else if(year >= 100 && year < 1000) {
					yearStr = "0" + year;
				} else if(year >= 1000) {
					yearStr = "" + year;
				}
				if(month < 10) {
					monthStr = "0" + month;
				} else {
					monthStr = "" + month;
				}
				if(datev < 10) {
					dateStr = "0" + datev;
				} else {
					dateStr = "" + datev;
				}
				if(hour < 10) {
					hourStr = "0" + hour;
				} else {
					hourStr = "" + hour;
				}
				if(minute < 10) {
					minuteStr = "0" + minute;
				} else {
					minuteStr = "" + minute;
				}
				if(second < 10) {
					secondStr = "0" + second;
				} else {
					secondStr = "" + second;
				}
				return yearStr + "-" + monthStr + "-" + dateStr + " " + hourStr + ":" + minuteStr + ":" + secondStr;
			}
			return null;
		}
	</script>
</div>
<br/>
<div onclick="fmt()"></div>
</body>
</html>